package com.wp.module.wpArticle.controller;

import com.wp.common.annotation.Log;
import com.wp.common.core.controller.BaseController;
import com.wp.common.core.domain.AjaxResult;
import com.wp.common.core.page.TableDataInfo;
import com.wp.common.enums.BusinessType;
import com.wp.common.utils.poi.ExcelUtil;
import com.wp.module.wpArticle.domain.WpArticle;
import com.wp.module.wpArticle.service.IWpArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 发布的帖子Controller
 * 
 * @author wp
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/module/wpArticle")
public class WpArticleController extends BaseController
{
    @Autowired
    private IWpArticleService wpArticleService;

    /**
     * 查询发布的帖子列表
     */
    @PreAuthorize("@ss.hasPermi('module:wpArticle:list')")
    @GetMapping("/list")
    public TableDataInfo list(WpArticle wpArticle)
    {
        startPage();
        List<WpArticle> list = wpArticleService.selectWpArticleList(wpArticle);
        return getDataTable(list);
    }

    /**
     * 导出发布的帖子列表
     */
    @PreAuthorize("@ss.hasPermi('module:wpArticle:export')")
    @Log(title = "发布的帖子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WpArticle wpArticle)
    {
        List<WpArticle> list = wpArticleService.selectWpArticleList(wpArticle);
        ExcelUtil<WpArticle> util = new ExcelUtil<WpArticle>(WpArticle.class);
        util.exportExcel(response, list, "发布的帖子数据");
    }

    /**
     * 获取发布的帖子详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:wpArticle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wpArticleService.selectWpArticleById(id));
    }

    /**
     * 新增发布的帖子
     */
    @PreAuthorize("@ss.hasPermi('module:wpArticle:add')")
    @Log(title = "发布的帖子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WpArticle wpArticle)
    {
        return toAjax(wpArticleService.insertWpArticle(wpArticle));
    }

    /**
     * 修改发布的帖子
     */
    @PreAuthorize("@ss.hasPermi('module:wpArticle:edit')")
    @Log(title = "发布的帖子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WpArticle wpArticle)
    {
        return toAjax(wpArticleService.updateWpArticle(wpArticle));
    }

    /**
     * 删除发布的帖子
     */
    @PreAuthorize("@ss.hasPermi('module:wpArticle:remove')")
    @Log(title = "发布的帖子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wpArticleService.deleteWpArticleByIds(ids));
    }
}
